<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>青橙，欢迎登录</title>
	<link rel="icon" href="./img/favicon.ico">

	<link rel="stylesheet" type="text/css" th:href="@{/css/elementui.css}" />
	<!--<link rel="stylesheet" type="text/css" href="./css/pages-login.css" />-->
	<link rel="stylesheet" type="text/css" href="./css/all.css" th:href="@{/css/all.css}" />
	<link rel="stylesheet" type="text/css" href="./css/pages-register.css" th:href="@{/css/pages-login.css}"/>
</head>

<body>
<div id="app">
	<!-- 头部栏位 -->
	<!--页面顶部-->
	<div id="nav-bottom">
		<!--顶部-->
		<div class="nav-top">
			<div class="top">
				<div class="py-container">
					<div class="shortcut">
						<ul class="fl">
							<li class="f-item">青橙欢迎您！</li>
							<li class="f-item">请<a href="javascript:void(0)" th:href="@{/loginUI}">登录</a>
								　<span><a href="javascript:void(0)" th:href="@{/registerUI}">免费注册</a></span></li>
						</ul>
						<div class="fr typelist">
							<ul class="types">
								<li class="f-item"><span>我的订单</span></li>

								<li class="f-item"><span><a href="cart.html">我的购物车</a></span></li>
								<li class="f-item"><span><a href="home.html">我的青橙</a></span></li>
								<li class="f-item"><span>青橙会员</span></li>
								<li class="f-item"><span>企业采购</span></li>
								<li class="f-item"><span>关注青橙</span></li>
								<li class="f-item"><span><a href="cooperation.html" >合作招商</a></span></li>
								<li class="f-item"><span><a href="shoplogin.html">商家后台</a></span></li>
								<li class="f-item"><span>网站导航</span></li>
							</ul>
						</div>

					</div>
				</div>
			</div>

			<!--头部-->
			<div class="header">
				<div class="py-container">
					<div class="yui3-g Logo">
						<div class="yui3-u Left logoArea">
							<a class="logo-bd" title="青橙"  href="javascript:void(0)" th:href="@{/index}" ></a>
						</div>
						<div class="yui3-u Rit searchArea">
							<div class="search">
								<form action="" class="sui-form form-inline">
									<!--searchAutoComplete-->
									<div class="input-append">
										<input type="text" id="autocomplete" class="input-error input-xxlarge" />
										<button class="sui-btn btn-xlarge btn-danger" type="button">搜索</button>
									</div>
								</form>
							</div>
						</div>

					</div>

				</div>
			</div>
		</div>
	</div>

	<div class="login-box">

		<!--loginArea-->
		<div class="loginArea">
			<div class="py-container login">
				<div class="loginform" style="height: 400px; top: 25px">
					<ul class="sui-nav nav-tabs tab-wraped">
						<li id="tabOtherLogin" onclick="switchOtherLogin()">
							<a href="javascript:void(0)" data-toggle="tab" >
								<h3>扫描登录</h3>
							</a>
						</li>
						<li id="tabSuiForm" class="active" onclick="switchSuiForm()">
							<a href="javascript:void(0)" data-toggle="tab" >
								<h3>账户登录</h3>
							</a>
						</li>
					</ul>
					<div class="tab-content tab-wraped" style="height: 320px" >
						<div id="index" class="tab-pane " >
<!--							微信登陆二维码 -->
							<iframe align="center" width="350px" height="330px"
									sandbox="allow-scripts allow-top-navigation allow-same-origin"
									src="http://localhost:8150/api/ucenter/wx/login" frameborder="no" border="0"
									marginwidth="0" marginheight="0" scrolling="no">
							</iframe>
						</div>
						<div id="profile" class="tab-pane active">
							<form class="sui-form">
								<div class="input-prepend"><span class="add-on loginname"></span>
									<input id="inputName" type="text"
										   placeholder="请输入手机号" v-model="pojo.phone" class="span2 input-xfat">
								</div>
								<div class="input-prepend"><span class="add-on loginpwd"></span>
									<input id="inputPassword" type="password"
										   placeholder="请输入密码" v-model="pojo.password" class="span2 input-xfat">
								</div>
								<div class="setting">
									<label class="checkbox inline">
										<input name="m1" type="checkbox" value="2" checked="">
										自动登录
									</label>
									<span class="forget">忘记密码？</span>
								</div>
								<div class="logined">
									<a class="sui-btn btn-block btn-xlarge btn-danger"  :plain="true"s
									   href="javascript:void(0)" @click="login()">登&nbsp;&nbsp;录</a>
								</div>
							</form>
							<div class="otherlogin">
								<div class="types">
									<ul>
										<li><img src="./img/qq.png" width="35px" height="35px" /></li>
										<li><img src="./img/sina.png" /></li>
										<li><img src="./img/ali.png" /></li>
										<li><img src="./img/weixin.png" /></li>
									</ul>
								</div>
								<span class="register"><a th:href="@{/registerUI}" >立即注册</a></span>
							</div>

						</div>
					</div>
				</div>
			</div>
		</div>
		<!--foot-->
		<div class="py-container copyright">
			<ul>
				<li>关于我们</li>
				<li>联系我们</li>
				<li>联系客服</li>
				<li>商家入驻</li>
				<li>营销中心</li>
				<li>手机品优购</li>
				<li>销售联盟</li>
				<li>品优购社区</li>
			</ul>
			<div class="address">地址：北京市昌平区建材城西路金燕龙办公楼一层 邮编：100096 电话：400-618-4000 传真：010-82935100</div>
			<div class="beian">京ICP备08001421号京公网安备110108007702</div>
		</div>
	</div>
</div>

<script type="text/javascript">
	function switchSuiForm() {
		document.getElementById('index').className = "tab-pane";
		document.getElementById('profile').className = "tab-pane active";
		document.getElementById('tabSuiForm').className = "active";
		document.getElementById('tabOtherLogin').className = "";
	}
	function switchOtherLogin() {
		document.getElementById('index').className = "tab-pane active";
		document.getElementById('profile').className = "tab-pane";
		document.getElementById('tabSuiForm').className = "";
		document.getElementById('tabOtherLogin').className = "active";
	}
</script>

<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/vue.js}"></script>
<script th:src="@{/js/axios.js}"></script>
<script th:src="@{/js/interceptor.js}"></script>
<script th:src="@{/js/elementui.js}"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>

<!--<script th:src="@{/js/js-cookie.js}"></script>-->
<script>
	var vue = new Vue({
		el: '#app',
		data() {
			return {
				pojo: {}
			}
		},
		methods: {
			login() {
				if(this.pojo.phone ==undefined){
					this.$message.error('手机号不能为空！！！');
					return ;
				}
				if (!(/^1[34578]\d{9}$/.test(this.pojo.phone))) {
					this.$message.error('手机号码格式不正确！！！');
					return ;
				}
				// 清空cookie值
				Cookies.set('qingcheng_token', '', {domain: 'localhost'})
				Cookies.set('qingcheng_user', '', {domain: 'localhost'})
				// console.log(this.pojo)
				// 登录
				axios.post('/portal/login', this.pojo).then(response => {
					if(response.data.message=='成功'){
						this.$message({
							message: '恭喜你，登陆成功',
							type: 'success'
						});
					}else {
						this.$message.error(response.data.data.token);
						// alert(response.data.data.token)
					}
					// alert(response.data.message);
					// console.log(this.pojo)
					// 获取token放入cookie中，需要导入js-cookie.js
					// 第1个参数是cookie名称，第二个参数是值，第三个参数作用范围
					// console.log(response)

					Cookies.set('qingcheng_token', response.data.data.token, {domain: 'localhost'})

					// 调用接口，根据token获取用户信息，在首页展示
					axios.get('/portal/getUserInfo').then(response => {
						Cookies.set('qingcheng_user', response.data.data.tbUser, {domain: 'localhost'})
						//跳转页面
						window.location.href="/portal/index"

					})
					this.pojo = {}
				});
			},

		}
	})
</script>
</body>
</html>